package com.spider.interface3;

public class ClassDataImpl2 implements ClassDataInter{
    private Student[] allStudent;
    public ClassDataImpl2(Student[] allStudent) {
        this.allStudent = allStudent;
    }
    @Override
    public void printAllStudentInfos() {
        int countf=0;
        int countm=0;
        for (int i=0;i <allStudent.length;i++)
        {
            Student s=allStudent[i];
            if (s.getSex()=='女')
                countf++;
            else
                countm++;
            System.out.println(s.getName()+" "+s.getSex()+" "+s.getScore());
        }
        System.out.println("女生个数："+countf);
        System.out.println("男生个数："+countm);
    }

    @Override
    public void printAverageScore() {
        //去掉最高分和最低分的平均分
        double sum=0;
        int max=0;
        int min=0;
        for (int i=0;i<allStudent.length;i++)
        {
            Student s=allStudent[i];
            sum+=s.getScore();
            if (s.getScore()>allStudent[ max].getScore())
                max=i;
            if (s.getScore()< allStudent[ min].getScore())
                min=i;
        }
        System.out.println("最高分："+ allStudent[ max]);
        System.out.println("最低分："+  allStudent[ min]);
        System.out.println("去掉最高分和最低分的平均分是："+(sum- allStudent[ max].getScore()- allStudent[ min].getScore())/(allStudent.length-2));
    }
}
